import { createRouter, createWebHistory } from 'vue-router'

export const routerFiles = import.meta.globEager(['../views/**/index.vue', '!**/components/**'])
const routeList = []
const upperName = name => 'Base' + name.split('/').map(da => da.replace(/^\w/g, d => d.toUpperCase())).join('')
for (const [key, component] of Object.entries(routerFiles)) {
  const path = key.replace('../views', '').replace('index.vue', 'list')
  const name = upperName((path).replace('/', ''))
  component.default.name = name
  routeList.push({
    path,
    name,
    component: async () => component,
    props: false,
    hidden: false,
    meta: {}
  })
}

export const routes = routeList
export const history = createWebHistory(import.meta.env.BASE_URL)

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})
export default router